1705A - Mark the Photographer - CodeForces Solution


greedy sortings *800

Please click on ads to support us..

Python Code:

r=lambda:map(int,input().split());t,=r();exec(t*"n,x=r();a=sorted(r());print('YNEOS'[any(v-u<x for u,v in zip(a[:n],a[n:]))::2]);")

C++ Code:

#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n, i, k, f=0, y;
    cin >> n >> k;
    int x = 2*n;
    vector<int> v, v1, v2;
    for(i=0; i<x; i++)
    {
        cin >> y;
        v.push_back(y);
    }
    sort(v.begin(),v.end());
    for(i=0; i<n; i++)
    {
        if(v[i+n]-v[i]<k)
        {
            f=1;
        }
    }
    if(f==1)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        solve();

    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence